#include <iostream>
#include <string>
using namespace std;

int main() {
    int t = 0;
    cin >> t;
    cin.ignore();
    while (t--) {
        int n = 0;
        int cnt_1 = 0;
        int cnt_0 = 0;
        int ans = 0;
        cin >> n;
        cin.ignore();
        string s="";
        cin >> s;
        for (int i = 0; i < n; i++) {
            if (s[i] == '1') {
                cnt_1++;
            }
        }
        cnt_0 = n - cnt_1;
        ans = cnt_1 * n - cnt_1 + cnt_0;
        cout << ans << endl;
    }
    return 0;
}